package com.ws.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ws.bean.VehicoleBrand;
import com.ws.common.CommonResult;
import com.ws.service.VehicleBrandService;
import com.ws.util.Page;

@RestController
@RequestMapping("brand")
public class VehicleBrandController {
	@Autowired
	VehicleBrandService service;
	@GetMapping("get")
	public CommonResult getBrands(VehicoleBrand brand , Page page) {
		List<VehicoleBrand> list = service.getBrands(brand,page);
		int count = service.getCount(brand);
		Map map = new HashMap();
		map.put("list",list);
		map.put("count", count);
		return CommonResult.success(map);
	}
	
	@PostMapping("add")
	public CommonResult addBrand(@RequestBody VehicoleBrand brand) {
		 int result = service.addBrand(brand);
		return CommonResult.success();
	}
	@PutMapping("edit")
	public CommonResult editBrand(VehicoleBrand brand) {
		int result = service.editBrand(brand);
		return CommonResult.success();
	}
	@DeleteMapping("del/{id}")
	public CommonResult delBrand(@PathVariable Integer id) {
		int result = service.delBrand(id);
		if(result == -1) return CommonResult.fail();
		return CommonResult.success();
	}
}
